package com.itheima.goods.controller;

import entity.Result;
import entity.StatusCode;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {


    @PostMapping("/login")
    public Result findAll(@RequestBody Map searchMap){
        searchMap.put("token", UUID.randomUUID());
        return new Result(true, StatusCode.OK,"登录成功",searchMap) ;
    }


    @GetMapping("/info")
    public Result findUser(String token){
        Map searchMap = new HashMap();
        searchMap.put("name", "admin");
        searchMap.put("roles", Arrays.asList("admin","user"));
        searchMap.put("avatar", "admin");
        return new Result(true, StatusCode.OK,"查询成功",searchMap) ;
    }

    @PostMapping("/logout")
    public Result logout(@RequestBody Map searchMap){
        return new Result(true, StatusCode.OK,"退出成功",searchMap) ;
    }

}
